package web.servlets;

import domain.Account;
import domain.Cart;
import domain.Order;
import persistence.AccountDAO;
import persistence.Impl.AccountDAOImple;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class NewOrderServlet extends HttpServlet {
    final static String NewOrder = "/WEB-INF/jsp/order/NewOrderForm.jsp";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Cart cart = (Cart) session.getAttribute("cart");
        AccountDAOImple accountDAOImple = new AccountDAOImple();
        Account account = accountDAOImple.getAccountByUsername((String) session.getAttribute("username"));
        Order order = new Order();
        order.initOrder(account,cart);
        session.setAttribute("order",order);

        req.getRequestDispatcher(NewOrder).forward(req,resp);
    }
}
